package com.sensePlusVR.bean;

import java.util.ArrayList;
import java.util.List;

import org.xutils.DbManager;
import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;
import org.xutils.ex.DbException;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;

import com.sensePlusVR.application.VRApplication;
import com.sensePlusVR.utils.MyLog;

/**
 * 
 * @author: Loren
 * @create: 2016-8-10下午2:58:59
 * @desc:notification item 
 *
 */
@Table(name = "FeedbackListRespDto")
public class FeedbackListRespDto implements Parcelable{
	private static final String TAG = FeedbackListRespDto.class.getSimpleName();
	@Column(name = "id",isId = true,autoGen = false)
	private Integer id;
	
	@Column(name = "feedback")
	private String feedback;
	
	@Column(name = "createTime")
	private String createTime;
	
	private ArrayList<FeedbackReplyItem> feedbackReplyList = new ArrayList<FeedbackReplyItem>();

	
	public FeedbackListRespDto() {
		
	}
	
	public FeedbackListRespDto(Parcel in){
		id = in.readInt();
		feedback = in.readString();
		createTime = in.readString();
		//in.readList(feedbackReplyList, FeedbackReplyItem.class.getClassLoader());
		in.readTypedList(feedbackReplyList, FeedbackReplyItem.CREATOR); 
		
	}

	public Integer getId() {
		return id;
	}


	public void setId(Integer id) {
		this.id = id;
	}


	public String getFeedback() {
		return feedback;
	}


	public void setFeedback(String feedback) {
		this.feedback = feedback;
	}


	public String getCreateTime() {
		return createTime;
	}


	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}



	public ArrayList<FeedbackReplyItem> getFeedbackReplyList() {
		return feedbackReplyList;
	}

	public void setFeedbackReplyList(ArrayList<FeedbackReplyItem> feedbackReplyList) {
		this.feedbackReplyList = feedbackReplyList;
	}

	@Override
	public String toString() {
		return "FeedbackRespDto [id=" + id + ", feedback=" + feedback
				+ ", createTime=" + createTime + ", feedbackReplyList="
				+ feedbackReplyList + "]";
	}


	@Override
	public int describeContents() {
		return 0;
	}


	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeInt(id);
		out.writeString(feedback);
		out.writeString(createTime);
		//out.writeList(feedbackReplyList);
		out.writeTypedList(feedbackReplyList);  
	}
	
	public static final Parcelable.Creator<FeedbackListRespDto> CREATOR = new Creator<FeedbackListRespDto>() {
		
		@Override
		public FeedbackListRespDto[] newArray(int size) {
			return new FeedbackListRespDto[size];
		}
		
		@Override
		public FeedbackListRespDto createFromParcel(Parcel in) {
			return new FeedbackListRespDto(in);
		}
	};
	
	public static void saveOrUpdate(Object object) {
		MyLog.d(TAG, "saveOrUpdate item : " + object.toString());
		try {
    		Context context = VRApplication.getAppContext();
    		if(context != null) {
    			DbManager db = VRApplication.getDbManager();
    			db.saveOrUpdate(object);
    		}
    	}catch(Exception e){
    		MyLog.e(TAG, "GameItem update failed: "+e);
    	}
	}
	
	public static List<FeedbackListRespDto> getFeedbackList(){
		Context context = VRApplication.getAppContext();
		if(context != null) {
			DbManager db = VRApplication.getDbManager();
			try {
				return db.selector(FeedbackListRespDto.class).orderBy("createTime",true).findAll();
			} catch (DbException e) {
				MyLog.e(TAG, "getGameListSort failed: "+e);
				return null;
			}
		}
		return null;
		
	}
	
	public static FeedbackListRespDto getFeedbackRespDtoById(Integer id){
		Context context = VRApplication.getAppContext();
		if(context != null) {
			DbManager db = VRApplication.getDbManager();
			try {
				return db.selector(FeedbackListRespDto.class).where("id", "=", id).findFirst();
			} catch (DbException e) {
				MyLog.e(TAG, "getFeedbackRespDtoById failed: "+e);
				return null;
			}
		}
		return null;
	}
	
	
}






